<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
//header('Content-type: text/html; charset=utf-8');


$time = date('r');
echo "data: The server time is: {$time}\n\n";
ob_flush();
flush();


function Conectarse() 
{ 
   if (!($link=mysql_connect("localhost","root",""))) 
   { 
      echo "Error conectando a la base de datos."; 
      exit(); 
   } 
   if (!mysql_select_db("facturacion",$link)) 
   { 
      echo "Error seleccionando la base de datos."; 
      exit(); 
   } 
   return $link; 
} 


 

   $link=Conectarse(); 
   $result=mysql_query("select * from producto",$link); 
      

   while($row = mysql_fetch_array($result)) { 
sendMsg($row[0], $row[1]);
//flush();

   } 
   mysql_free_result($result); 
   mysql_close($link); 



function sendMsg($id, $msg) {
  

  echo "id: $id" . PHP_EOL;
  echo "data: $msg" . PHP_EOL;
  echo PHP_EOL;
  ob_flush();
  flush();

}



//  sendMsg($row[0], $row[1]);


?>